#include "FileDirectory.h"
using namespace std;

FileDirectory::FileDirectory(IWbemClassObject* pclsObj)
{
    _pclsObj = pclsObj;
    setProperties();
}

FileDirectory::~FileDirectory()
{

}

void FileDirectory::setProperties()
{
    VARIANT vtProp;
    HRESULT hr;

    hr = _pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {            
        setName(wstring(vtProp.bstrVal));
    }

    hr = _pclsObj->Get(L"Caption", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setCaption(wstring(vtProp.bstrVal));
    }

    hr = _pclsObj->Get(L"Status", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setStatus(wstring(vtProp.bstrVal));
    }

    hr = _pclsObj->Get(L"Description", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setStatus(wstring(vtProp.bstrVal));
    }

    hr = _pclsObj->Get(L"InstallDate", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setInstallDate(Utils::wcharToCTime(vtProp.bstrVal));            
    }

    hr = _pclsObj->Get(L"CreationDate", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setCreationDate(Utils::wcharToCTime(vtProp.bstrVal));            
    }

    hr = _pclsObj->Get(L"LastAccessed", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setLastAccessed(Utils::wcharToCTime(vtProp.bstrVal));            
    }

    hr = _pclsObj->Get(L"LastModified", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setLastModified(Utils::wcharToCTime(vtProp.bstrVal));            
    }

    hr = _pclsObj->Get(L"Writeable", 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setWriteable(vtProp.boolVal);            
    }

    VariantClear(&vtProp);

}

const wstring& FileDirectory::getCaption()
{
    return _caption;
}

void FileDirectory::setCaption(const wstring& caption)
{
    _caption = caption;
}

const wstring& FileDirectory::getDescription()
{
    return _description;
}

void FileDirectory::setDescription(const wstring& des)
{
    _description = des;
}

const wstring& FileDirectory::getName()
{
    return _name;
}

void FileDirectory::setName(const wstring& name)
{
    _name = name;
}

const wstring& FileDirectory::getStatus()
{
    return _status;
}

void FileDirectory::setStatus(const wstring& status)
{
    _status = status;
}

const CTime& FileDirectory::getInstallDate()
{
    return _installDate;
}

void FileDirectory::setInstallDate(const CTime& time)
{
    _installDate = time;
}

const CTime& FileDirectory::getCreationDate()
{
    return _creationDate;
}

void FileDirectory::setCreationDate(const CTime& time)
{
    _creationDate = time;
}

const CTime& FileDirectory::getLastAccessed()
{
    return _lastAccessed;
}

void FileDirectory::setLastAccessed(const CTime& time)
{
    _lastAccessed = time;
}

const CTime& FileDirectory::getLastModified()
{
    return _lastModified;
}

void FileDirectory::setLastModified(const CTime& time)
{
    _lastModified = time;
}

const bool FileDirectory::isWriteable()
{
    return _writeable;
}

void FileDirectory::setWriteable(bool wri)
{
    _writeable = wri;
}

void FileDirectory::toString()
{
    wcout << L"Name :" << getName() << endl;
}